package com.spddr.pmos.cxf.tree.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.springframework.stereotype.Service;

import com.spddr.pmos.cxf.tree.JaxrsTradeTree;
import com.spddr.pmos.jpa.Grid;

import cn.seqdata.pojo.TreeNode;


@Service
public class JaxrsTradeTreeImpl extends AbstractTreeImpl implements JaxrsTradeTree {

	@Override
	public Collection<TreeNode> byRoot() {
		List<TreeNode> nodes = new ArrayList<>();
		Grid grid = gridRepos.findOne(51L);
		nodes.addAll(byJpaObject(true, Arrays.asList(grid)));
		return nodes;
	}

	@Override
	public Collection<TreeNode> byGrid(long grid) {
		return byJpaObject(true, Arrays.asList(companyRepos.findOne(1000000L)));
	}

	@Override
	public Collection<TreeNode> byCompany(long company) {
		List<TreeNode> nodes = new ArrayList<>();
		nodes.addAll(byJpaObject(true, companyRepos.findByParentId(company)));
		if (company == 10000004) {
			nodes.addAll(byJpaObject(false, customerRepos.findAll()));
		}
		return nodes;
	}
}
